package com.sc.nft.admin.controller;

import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.AddAPermissionPackageDTO;
import com.sc.nft.dto.GetsAllPermissionPackagesDTO;
import com.sc.nft.dto.IdRequest;
import com.sc.nft.feign.MerchantExtraPermissionClient;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import com.sc.nft.vo.GetsAllPermissionPackagesVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 额外的权限包(MerchantExtraPermission)表控制层
 *
 * @author wwc
 * @since 2023-03-28 11:05:07
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/merchantExtraPermission")
@Api(tags = "额外权限包操作")
public class MerchantExtraPermissionController {

    /**
     * 服务对象
     */
    private final MerchantExtraPermissionClient merchantExtraPermissionClient;

    @PostMapping(value = "addAPermissionPackage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增一个权限包", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addAPermissionPackage(@RequestBody @Validated AddAPermissionPackageDTO addAPermissionPackageDTO) {
        merchantExtraPermissionClient.addAPermissionPackage(addAPermissionPackageDTO);
        return Result.success();
    }


    @PostMapping(value = "getsAllPermissionPackages", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取所有权限包", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<GetsAllPermissionPackagesVO> getsAllPermissionPackages(@RequestBody @Validated GetsAllPermissionPackagesDTO getsAllPermissionPackages) {
        return merchantExtraPermissionClient.getsAllPermissionPackages(getsAllPermissionPackages);
    }


    @PostMapping(value = "deletePermissionPackage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除权限包,该权限包删除后下属所有权限都将失效", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deletePermissionPackage(@RequestBody @Validated IdRequest idRequest) {
        merchantExtraPermissionClient.deletePermissionPackage(idRequest);
        return Result.success();
    }
}
